package client.comm.snackbar;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.snackbar.Snackbar;

public class SnackBarActivity extends AppCompatActivity {

    TextView textView;
    Handler handler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.snackbart_layout);
        textView = findViewById(R.id.msgTv);
        textView.setText(getIntent().getStringExtra("msg"));

        findViewById(R.id.viewWrap).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Log.d("DDD", "wrap点击");
            }
        });
        handler = new Handler(getMainLooper(), new Handler.Callback() {
            @Override
            public boolean handleMessage(@NonNull Message msg) {

                switch (msg.what) {
                    case 0:
                        Log.d("DD", "SnackBarActivity fff");
                        finish();
                        overridePendingTransition(R.anim.pop_in, R.anim.pop_out);
                        break;
                }
                return false;
            }
        });
        handler.sendEmptyMessageDelayed(0, 1000);
    }


    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (!TextUtils.isEmpty(intent.getStringExtra("msg"))) {
            ((TextView) findViewById(R.id.msgTv)).setText(intent.getStringExtra("msg"));
        }
        handler.removeMessages(0);
        handler.sendEmptyMessageDelayed(0, 1000);
    }


    @Override
    protected void onDestroy() {
        handler.removeMessages(0);
        super.onDestroy();
    }

}
